#pragma once

namespace Tmpl {

// ===========================================================
// WidgetSet
// ===========================================================

struct WidgetSetData;
class WidgetSet : public Widget
{
public:
	enum Order {UNORDERED, SPREAD, LEFT, RIGHT, TOP, BOTTOM, CENTER};
	enum WidgetSetType
	{
		ORDENED_SET,
		LABELED_SET,
		TABS
	};

	WidgetSet(const char* label, int w, int h, int x=0, int y=0);
	WidgetType GetType() const {return Widget::WIDGETSET;}
	virtual WidgetSetType GetSetType() const = 0;

	void SetPos(int x, int y);
	void SetSize(int w, int h);

	virtual void Tick(float deltaTime);
	virtual void Draw();
	virtual void Refit(){}
protected:
	WidgetSetData* myData;
};

// ===========================================================
// Specialized sets
// ===========================================================

class OrdenedSet : public WidgetSet
{
public:
	OrdenedSet(const char* label, int w, int h, int x=0, int y=0);
	WidgetSetType GetSetType() const {return ORDENED_SET;}
	void SetOrdering(bool horizontal, Order orderH, Order orderV);

	virtual void Refit();
	virtual void TightFit();

	void AddWidget(Widget* widget);
	void AddSpacing(int space);
	
private:
	Order myOrderH, myOrderV;
	bool myIsHorizontal;
};

class LabeledSet : public OrdenedSet
{
public:
	LabeledSet(const char* label, int w, int h, int x=0, int y=0, bool collapsable=false);
	WidgetSetType GetSetType() const {return LABELED_SET;}

	void Tick(float deltaTime);
	void Draw();
	void Refit();
	void TightFit();
private:
	bool myIsCollapsable, myIsCollapsed;
};

struct TabsDataImp;
class Tabs : public WidgetSet
{
public:
	Tabs(const char* label, int w, int h, int x=0, int y=0, int tabHeight=16);
	WidgetSetType GetSetType() const {return TABS;}

	Widget* GetTab(int index);
	void AddTab(const char* tabName, Widget* tab=0);

	int GetSelected() const		{return myIsSelected;}
	void SetSelected(int index)	{myIsSelected = index;}

	virtual void Tick(float deltaTime);
	virtual void Draw();
	virtual void Refit();
private:
	void _CalcTabWidths();
	TabsDataImp* myData;
	int myIsMouseOverTab;
	int myIsSelected, myTabsH;
};

}; // namespace tmpl